import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate';
import * as types from './mutation-type';

Vue.use(Vuex);

const state = {
    userInfo: {},
    articleInfo: {
        isTop: false,
        isSpecialRecommend: false
    }
};

const plugins = [
    createPersistedState({
        storage: window.sessionStorage
    })
];

const mutations = {
    [types.SET_USER_INFO] (state, userInfo) {
        state.userInfo = userInfo;
    },
    [types.SET_ARTICLE_INFO] (state, articleInfo) {
        state.articleInfo = articleInfo;
    }
};

export const store = new Vuex.Store({
    state,
    mutations,
    plugins
});
